Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

358
Visualizações
Load PDF document with PDF-LIB on Node gives "No PDF header found"

Im loading a PDF document I have to modify on the fly with PDF-lib.

const { PDFDocument } = require('pdf-lib');

The PDF file is built with Acrobat and its called dental_insurance.pdf.

I tried to load the file the following ways:

const pdfDoc = await PDFDocument.load("/documents/cards/dental_insurance.pdf")

const pdfDoc = await PDFDocument.load("C:/Website/test/desk_routes/documents/cards/dental_insurance.pdf")

const pdfDoc = await PDFDocument.load("./documents/cards/dental_insurance.pdf")

const pdfDoc = await PDFDocument.load("../documents/cards/dental_insurance.pdf")

But no matter how I set the route where the file is located, I get this error:

(node:15196) UnhandledPromiseRejectionWarning: Error: Failed to parse PDF document (line:4 col:2 offset=27): No PDF header found

I checked at PDF-lib documentation, they only state the following to load a file:

const pdfDoc = await PDFDocument.load("...")

I dont believe the problem is on the PDF file since I get the very same error even if I enter a file that doesn't exist:

const pdfDoc = await PDFDocument.load("blablabla.pdf")

Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Per the documentation, PDFDocument.load() accepts a string which is the contents of the pdf file, not the name.

const fs = require('fs/promises');

const pdfData = await fs.readFile('./documents/cards/dental_insurance.pdf');

const pdfDoc = await PDFDocument.load(pdfData);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda